package dao

import (
	"context"
	"mall-portalv2/internal/model"
)

func (d *Dao) QueryUmsMemberReceiveAddressAllWhereMemberID(ctx context.Context, MemberID int64) ([]model.UmsMemberReceiveAddress, error) {
	tb := model.UmsMemberReceiveAddress{}
	result := []model.UmsMemberReceiveAddress{}

	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("member_id = ?", MemberID).Order("default_status DESC, id DESC").Find(&result).Error; err != nil {
		return result, err
	}
	return result, nil
}

func (d *Dao) QueryUmsMemberReceiveAddressWhereID(ctx context.Context, ID int64) (model.UmsMemberReceiveAddress, error) {
	tb := model.UmsMemberReceiveAddress{}
	result := model.UmsMemberReceiveAddress{}

	if err := d.db.WithContext(ctx).Table(tb.TableName()).Where("id = ?", ID).First(&result).Error; err != nil {
		return result, err
	}
	return result, nil
}
